import { Button, Tooltip } from 'antd';
import { Fragment } from 'react';
import { AssetacquisitionManageAPI } from '../common/type';
import { EditOutlined, RollbackOutlined, DeleteOutlined } from '@ant-design/icons';
import pageStyles from '@/common/pageLayout.less';
import { ManageCommonAPI } from '@/pages/type';
import { tableMoreBtnConfig } from '@/utils/myutilConfig';
import { getColorTextLoadMap, getTenantID, getUserID, removeDateHmsStr } from '@/utils';
import MyIcon from '@/components/MyIcon';
import { ColumnsRenderFun, DictionaryRenderFun } from '../../Acommon';
import { ILoadMapTypeAll } from '@/common';

/**操作按钮的显示*/
const Operation = (curRes: Record<string, any>, operateFuns: AssetacquisitionManageAPI.IMaterialTableActionType, record: Record<string, any>) => {
  let operationArray: any = [];

  /** 一个按钮都没有时展示*/
  const Disable = (
    <Fragment key={record?.id + '--Disable'}>
      <Button style={{ color: '#000' }} className="manageBtntTxtStyle" type={'link'} size={'small'} disabled>
        --
      </Button>
    </Fragment>
  );

  // 没有审批状态 并且 申请状态在起草  显示可以编辑
  const editVisible: boolean =
    curRes?.['/assetApplyHandle/edit'] && !record?.checkState && record?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_HANDLE_STATUS}1000`;
  // 没有审批状态或者审批被退回 并且 申请状态在起草  显示可以提交
  const submitVisible: boolean =
    (!record?.checkState && record?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_HANDLE_STATUS}1000`) ||
    (record?.checkState == `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1003` &&
      record?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_HANDLE_STATUS}1002`);

  const cancelVisible: boolean =
    (!record?.checkState && record?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_HANDLE_STATUS}1000`) ||
    (record?.checkState == `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1003` &&
      record?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_HANDLE_STATUS}1002`);

  const revokeVisible: boolean =
    record?.checkState == `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_CHECKRESULT}1000` &&
    record?.state == `${getTenantID()}${ILoadMapTypeAll.STORAGE_HANDLE_STATUS}1001` &&
    record?.createrID == getUserID();

  /** 更多按钮配置 */
  const otherBtnConfig: ManageCommonAPI.TableMoreBtnConfigApi[] = [
    {
      icon: <EditOutlined />,
      btnName: '编辑',
      clickFnc: operateFuns,
      clickType: 'onEdit',
      isVisible: editVisible,
    },
    // {
    //   icon: <CheckCircleOutlined />,
    //   btnName: '提交',
    //   clickFnc: operateFuns,
    //   clickType: 'onSubmit',
    //   isVisible: false, // submitVisible
    // },
    {
      icon: <DeleteOutlined />,
      btnName: <span>删除</span>,
      clickFnc: operateFuns,
      clickType: 'onCancel',
      isVisible: cancelVisible,
    },
    // {
    //   icon: <RollbackOutlined />,
    //   btnName: <span>撤销</span>,
    //   clickFnc: operateFuns,
    //   clickType: 'onRevoke',
    //   isVisible: revokeVisible,
    // },
    // {
    //   icon: <EditOutlined />,
    //   btnName: 'OA',
    //   clickFnc: operateFuns,
    //   clickType: 'onOA',
    //   // 没有审批状态 并且 申请状态在起草  显示可以编辑
    //   isVisible: true,
    // },
  ];
  const ohterBtn = tableMoreBtnConfig(otherBtnConfig, record);
  operationArray = ohterBtn;
  operationArray = operationArray?.filter((itemBtn: any) => itemBtn);
  return operationArray && operationArray?.length > 0 ? operationArray : [Disable];
};

// Table表格的配置
const getTableColumns = (curRes: Record<string, any>, operateFuns: AssetacquisitionManageAPI.IMaterialTableActionType) => {
  const { onView } = operateFuns;
  return [
    {
      title: '申请部门/单位',
      dataIndex: 'createDepartmentName',
      key: 'createDepartmentName',
      fixed: 'left',
      width: 150,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.createDepartmentName > b?.createDepartmentName ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '事项名称',
      dataIndex: 'applyTitle',
      key: 'applyTitle',
      fixed: 'left',
      width: 130,
      unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.applyTitle > b?.applyTitle ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <a className={pageStyles['over-flow-hidden']} onClick={() => onView(record)}>
              {text || '--'}
            </a>
          </Tooltip>
        );
      },
    },

    {
      title: '事由',
      dataIndex: 'applyInfo',
      key: 'applyInfo',
      width: 130,
      visible: false,
      sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
      render: (text: string, record: any) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || ''}</div>
          </Tooltip>
        );
      },
    },

    {
      title: '报废类别',
      dataIndex: 'repealType',
      key: 'repealType',
      width: 130,
      visible: true,
      sorter: (a: any, b: any) => (a?.repealType > b?.repealType ? 1 : -1),
      render: (text: string) => {
        let valStr = text == '0' ? '年限到期' : text == '1' ? '设备老化' : text == '2' ? '以旧换新' : text == '3' ? '其他' : '--';
        return (
          <Tooltip title={valStr}>
            <div className={pageStyles['over-flow-hidden']}>{valStr}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '风险程度',
      dataIndex: 'riskLevel',
      key: 'riskLevel',
      width: 130,
      visible: true,
      sorter: (a: any, b: any) => (a?.riskLevel > b?.riskLevel ? 1 : -1),
      render: (text: string) => {
        let valStr = text == '0' ? '暂无风险' : text == '1' ? '低风险' : text == '2' ? '中风险' : text == '3' ? '高风险' : '--';
        return (
          <Tooltip title={valStr}>
            <div className={pageStyles['over-flow-hidden']}>{valStr}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '状态',
      dataIndex: 'stateName',
      key: 'stateName',
      width: 100,
      visible: true,
      sorter: (a: any, b: any) => (a?.stateName > b?.stateName ? 1 : -1),
      render: (text: number) => DictionaryRenderFun({ text, isTooltip: true, isState: true }),
    },
    {
      title: '申请时间',
      dataIndex: 'createTime',
      key: 'createTime',
      width: 100,
      visible: true,
      sorter: (a: any, b: any) => (a?.createTime > b?.createTime ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{removeDateHmsStr(text) || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '申请人单位',
      dataIndex: 'createCompanyName',
      key: 'createCompanyName',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.createCompanyName > b?.createCompanyName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '申请人部门',
      dataIndex: 'createDepartmentName',
      key: 'createDepartmentName',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.createDepartmentName > b?.createDepartmentName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '申请人岗位',
      dataIndex: 'createPositionName',
      key: 'createPositionName',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.createPositionName > b?.createPositionName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '申请人',
      dataIndex: 'createrName',
      key: 'createrName',
      width: 100,
      visible: true,
      sorter: (a: any, b: any) => (a?.createrName > b?.createrName ? 1 : -1),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '修改时间',
      dataIndex: 'modifyTime',
      key: 'modifyTime',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.modifyTime > b?.modifyTime ? 1 : -1),
      render: (text: string) => <span>{removeDateHmsStr(text)}</span>,
    },
    {
      title: '修改人单位',
      dataIndex: 'modifyCompanyName',
      key: 'modifyCompanyName',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.modifyCompanyName > b?.modifyCompanyName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '修改人部门',
      dataIndex: 'modifyDepartmentName',
      key: 'modifyDepartmentName',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.modifyDepartmentName > b?.modifyDepartmentName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '修改人岗位',
      dataIndex: 'modifyPositionName',
      key: 'modifyPositionName',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.modifyPositionName > b?.modifyPositionName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '修改人',
      dataIndex: 'modifyerName',
      key: 'modifyerName',
      visible: false,
      width: 100,
      sorter: (a: any, b: any) => (a?.modifyerName > b?.modifyerName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },

    {
      title: '作废类型', //数据字典
      dataIndex: 'cancelTypeName',
      key: 'cancelTypeName',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.cancelTypeName > b?.cancelTypeName ? 1 : -1),
      render: (text: string | null) => DictionaryRenderFun({ text }),
    },
    {
      title: '作废原因',
      dataIndex: 'cancelReason',
      key: 'cancelReason',
      visible: false,
      width: 180,
      sorter: (a: any, b: any) => (a?.cancelReason > b?.cancelReason ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '作废时间',
      dataIndex: 'cancelTime',
      key: 'cancelTime',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.cancelTime > b?.cancelTime ? 1 : -1),
      render: (text: string) => <span>{removeDateHmsStr(text)}</span>,
    },
    {
      title: '作废人单位',
      dataIndex: 'cancelCompanyName',
      key: 'cancelCompanyName',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.cancelCompanyName > b?.cancelCompanyName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '作废人部门',
      dataIndex: 'cancelDepartmentName',
      key: 'cancelDepartmentName',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.cancelDepartmentName > b?.cancelDepartmentName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '作废人岗位',
      dataIndex: 'cancelPositionName',
      key: 'cancelPositionName',
      visible: false,
      width: 150,
      sorter: (a: any, b: any) => (a?.cancelPositionName > b?.cancelPositionName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '作废人',
      dataIndex: 'cancelerName',
      key: 'cancelerName',
      visible: false,
      width: 100,
      sorter: (a: any, b: any) => (a?.cancelerName > b?.cancelerName ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: 130,
      visible: true,
      unDrag: true,
      align: 'center',
      fixed: 'right',
      render: (text: string | null, record: Record<string, any>) => {
        return <div style={{ display: 'flex' }}>{Operation(curRes, operateFuns, record)}</div>;
      },
    },
  ];
};

export { getTableColumns };
// {
//   title: '申请编号',
//   dataIndex: 'applyCode',
//   key: 'applyCode',
//   width: 150,
//   unDrag: true,
//   visible: true,
//   sorter: (a: any, b: any) => (a?.applyCode > b?.applyCode ? 1 : -1),
//   render: (text: string, record: any) => {
//     return (
//       <Tooltip title={text}>
//         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '审核状态',
//   dataIndex: 'checkStateName',
//   key: 'checkStateName',
//   width: 150,
//   unDrag: true,
//   visible: true,
//   sorter: (a: any, b: any) => (a?.checkStateName > b?.checkStateName ? 1 : -1),
//   render: (text: string) => {
//     let colorText = getColorTextLoadMap(text)?.colorText;
//     let color = getColorTextLoadMap(text)?.color;
//     return (
//       <Tooltip>
//         <MyIcon type="icon-dian" style={{ color: color }} />
//         <span style={{ color: color }}>{colorText ? colorText : '--'}</span>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '风险程度',
//   dataIndex: 'riskLevel',
//   key: 'riskLevel',
//   width: 150,
//   unDrag: true,
//   visible: true,
//   sorter: (a: any, b: any) => (a?.riskLevel > b?.riskLevel ? 1 : -1),
//   render: (text: string) => {
//     return (
//       <Tooltip title={text}>
//         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '报废类别',
//   dataIndex: 'repealType',
//   key: 'repealType',
//   width: 150,
//   unDrag: true,
//   visible: true,
//   sorter: (a: any, b: any) => (a?.repealType > b?.repealType ? 1 : -1),
//   render: (text: string) => {
//     return (
//       <Tooltip title={text}>
//         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '损坏类型',
//   dataIndex: 'damageType',
//   key: 'damageType',
//   width: 150,
//   unDrag: true,
//   visible: true,
//   sorter: (a: any, b: any) => (a?.damageType > b?.damageType ? 1 : -1),
//   render: (text: string) => {
//     return (
//       <Tooltip title={text}>
//         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '索赔类型',
//   dataIndex: 'claimType',
//   key: 'claimType',
//   width: 150,
//   unDrag: true,
//   visible: true,
//   sorter: (a: any, b: any) => (a?.claimType > b?.claimType ? 1 : -1),
//   render: (text: string) => {
//     return (
//       <Tooltip title={text}>
//         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '索赔原因',
//   dataIndex: 'claimReason',
//   key: 'claimReason',
//   width: 150,
//   unDrag: true,
//   visible: true,
//   sorter: (a: any, b: any) => (a?.claimReason > b?.claimReason ? 1 : -1),
//   render: (text: string) => {
//     return (
//       <Tooltip title={text}>
//         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '申请理由',
//   dataIndex: 'applyInfo',
//   key: 'applyInfo',
//   width: 150,
//   unDrag: true,
//   visible: true,
//   sorter: (a: any, b: any) => (a?.applyInfo > b?.applyInfo ? 1 : -1),
//   render: (text: string, record: any) => {
//     return (
//       <Tooltip title={text}>
//         <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '申请文件',
//   dataIndex: 'applyFile',
//   key: 'applyFile',
//   width: 150,
//   unDrag: true,
//   visible: true,
//   sorter: (a: any, b: any) => (a?.applyFile > b?.applyFile ? 1 : -1),
//   render: (text: string, record: any) => {
//     return (
//       <div
//         style={{
//           height: '100%',
//           display: 'flex',
//           alignItems: 'center',
//           marginLeft: '8px',
//         }}
//       >
//         {record?.['applyFile']
//           ? splitFileUrl(record?.['applyFile'])?.map((e, i) => {
//               return (
//                 <Tooltip title={e.attachName} key={new Date().getTime() * 25615265152 + e?.attachName}>
//                   <a
//                     className={pageStyles['over-flow-hidden']}
//                     onClick={() => {
//                       message.success('下载中，请稍后...');
//                       downloadTemplate('/assetInfo/downloadFile', e?.attachName, e?.attachUrl, () => {});
//                     }}
//                   >
//                     <MyIcon type="icon-file-text-fill" />
//                     &nbsp;
//                     {getFileNameNotType(e.attachName, 8)}
//                   </a>
//                 </Tooltip>
//               );
//             })
//           : '--'}
//       </div>
//     );
//   },
// },
// {
//   title: '创建时间',
//   dataIndex: 'createTime',
//   key: 'createTime',
//   visible: false,
//   width: 150,
//   sorter: (a: any, b: any) => (a?.createTime > b?.createTime ? 1 : -1),
//   render: (text: string) => <span>{removeDateHmsStr(text)}</span>,
// },
// {
//   title: '创建人单位',
//   dataIndex: 'createCompanyName',
//   key: 'createCompanyName',
//   visible: false,
//   width: 150,
//   sorter: (a: any, b: any) => (a?.createCompanyID > b?.createCompanyID ? 1 : -1),
//   render: (text: string | null) => ColumnsRenderFun({ text }),
// },
// {
//   title: '创建人部门',
//   dataIndex: 'createDepartmentName',
//   key: 'createDepartmentName',
//   visible: false,
//   width: 150,
//   sorter: (a: any, b: any) => (a?.createDepartmentName > b?.createDepartmentName ? 1 : -1),
//   render: (text: string | null) => ColumnsRenderFun({ text }),
// },
// {
//   title: '创建人岗位',
//   dataIndex: 'createPositionName',
//   key: 'createPositionName',
//   visible: false,
//   width: 150,
//   sorter: (a: any, b: any) => (a?.createPositionName > b?.createPositionName ? 1 : -1),
//   render: (text: string | null) => ColumnsRenderFun({ text }),
// },
// {
//   title: '创建人',
//   dataIndex: 'createrName',
//   key: 'createrName',
//   visible: false,
//   width: 150,
//   sorter: (a: any, b: any) => (a?.createrName > b?.createrName ? 1 : -1),
//   render: (text: string | null) => ColumnsRenderFun({ text }),
// },
